package com.docker.sys.role.rolePerm;

import com.docker.core.constant.APPIDConstant;
import com.docker.core.mvc.APPID;
import com.docker.core.mvc.Remark;
import com.docker.core.mvc.controller.BaseAPIController;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Okv;
import com.jfinal.kit.StrKit;

/**
 * @Author ldl
 * @Create 2020/11/30 030 17:15
 */
@Remark("系统角色权限")
@APPID(APPIDConstant.dum_web)
public class RolePermController extends BaseAPIController {

    @Inject
    private RolePermService rolePermService;

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/11/30 030 16:11
     */
    @Remark("角色权限树")
    public void tree() {
        Okv cond = Okv.create()
                .set("p.status_flag = ", "1");
        if (StrKit.notBlank(getPara("perm_name"))) {
            cond.set("p.perm_name like ", "%" + getPara("perm_name") + "%");
        }
        if (StrKit.notBlank(getPara("perm_desc"))) {
            cond.set("p.perm_desc like ", "%" + getPara("perm_desc") + "%");
        }
        if (StrKit.notBlank(getPara("action_key"))) {
            cond.set("p.action_key like ", "%" + getPara("action_key") + "%");
        }
        if (StrKit.notBlank(getPara("controller"))) {
            cond.set("p.controller like ", "%" + getPara("controller") + "%");
        }
        if (StrKit.notBlank(getPara("controller_name"))) {
            cond.set("p.controller_name like ", "%" + getPara("controller_name") + "%");
        }
        renderAPISuccess(rolePermService.tree(Okv.by("cond", cond).set("role_id", getPara("role_id")).set("app_id", getPara("app_id_ex"))));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/11/30 030 16:56
     */
    @Remark("添加角色权限")
    public void save() {
        renderAPI(rolePermService.save(getPara("role_id"), getPara("perm_id")));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/11/30 030 17:01
     */
    @Remark("删除角色权限")
    public void delete() {
        renderAPI(rolePermService.delete(getPara("role_id"), getPara("perm_id")));
    }

}
